package polyu.comp;


import android.app.*;
import android.content.*;
import android.os.*;
import android.widget.*;
import android.widget.TabHost.*;



public class RunkingActivity extends TabActivity {
	
	/**
	 * Initialize the preference for the first time
	 */
	public void initApp() {
		
		// Turn off strict mode.
		
		StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
		StrictMode.setThreadPolicy(policy);
		
		String fileName = getResources().getString(R.string.app_name);
		SharedPreferences settings = getSharedPreferences(fileName, 0);
		
		if(settings.getString("uid", "noname").equalsIgnoreCase("noname"))
			Util.updatePref(this);
		else
			Util.updateData(this);
		
		// ONLY Call this time
		DataManager.instance().setContext(this);
		DataManager.instance().initFromLocalFile();
		
	}
	
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.main);
	    
	    // The application initialized
	    // add default preference
	    this.initApp();

	    //Resources res = getResources(); // Resource object to get Drawables
	    TabHost tabHost = getTabHost();  // The activity TabHost
	    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
	    Intent intent;  // Reusable Intent for each tab

	    // Create an Intent to launch an Activity for the tab (to be reused)
	    intent = new Intent().setClass(this, RecentActivity.class);
	    // Initialize a TabSpec for each tab and add it to the TabHost
	    spec = tabHost.newTabSpec("recent").setIndicator("What's New")
	                  .setContent(intent);
	    tabHost.addTab(spec);
	    
	    intent = new Intent().setClass(this, MyActivity.class);
	    spec = tabHost.newTabSpec("my").setIndicator("My Activity")
	                  .setContent(intent);
	    tabHost.addTab(spec);

	    // Do the same for the other tabs
	    intent = new Intent().setClass(this, RankActivity.class);
	    spec = tabHost.newTabSpec("rank").setIndicator("Ranks")
	                  .setContent(intent);
	    tabHost.addTab(spec);

	    intent = new Intent().setClass(this, SettingActivity.class);
	    spec = tabHost.newTabSpec("setting").setIndicator("Settings")
	                  .setContent(intent);
	    tabHost.addTab(spec);

	    // set height
	    for(int i = 0; i < tabHost.getTabWidget().getChildCount(); i++)
	    {
	    	int h = tabHost.getTabWidget().getChildAt(i).getLayoutParams().height;
	    	tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = h/2;
	    }
	    
	    tabHost.setOnTabChangedListener(new OnTabChangeListener() {
			@Override
			public void onTabChanged(String tabId) {
				if (tabId.equals("rank")) {
					 ;
				}
				
			}
		});
	    
	}
}
